﻿#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include "n2base.h"
#include "n2link.h"
#include "SymbolTable.h"

SymbolTable * global_syms = NULL;
SymbolTable * comdat_syms = NULL;
SymbolTable * weak_syms = NULL;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

UniverTabItem* SymbolTable::allocGroupData(size_t count)
{
    return new Symbol[count];
}

Symbol* SymbolTable::getSymbol(size_t index)
{
    return static_cast<Symbol*> (getItem(index));
}

SymbolTable::SymbolTable(size_t  groupCubage) : UniverTab(groupCubage)
{
}

SymbolTable::SymbolTable() : UniverTab(1024)
{
}

void Symbol::moveFrom(UniverTabItem *p)
{
    Symbol * pSym;
    pSym = static_cast <Symbol *> (p);

    m_symbolName.setstr(pSym->m_symbolName.c_str());
    sym = pSym->sym;
    m_globalSectionId = pSym->m_globalSectionId;
    m_extType = pSym->m_extType;
    m_isAuxSym = pSym->m_isAuxSym;
    m_auxtype = pSym->m_auxtype;
    ////
    m_boSameNameSym = pSym->m_boSameNameSym;
    m_next = pSym->m_next;              // for same name use
}

void Symbol::copyFrom(const UniverTabItem *p)
{
    return;
}

UniverTabItem * Symbol::getOffsetItem(size_t index)
{
    return &this[index];
}

Symbol::Symbol(){}

Symbol::Symbol(const Coff32_Symb *pCoff32Symbol, const char * name)
{
    m_symbolName.setstr(name);
    sym.base = *pCoff32Symbol;
    m_globalSectionId = 0;
    m_extType = 0;
    m_isAuxSym = false;
    m_auxtype = 0;
    ////
    m_boSameNameSym = false;
    m_next = NULL;                    // for same name use
}

Symbol::~Symbol()
{
    // if there are same name symbol record, need to free them
    if (!m_boSameNameSym && m_next)
    {
    }
}

